{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting started with brianrender\n",
    "This notebooks shows how to get started using brainrender.\n",
    "It assumes that you have already installed, if not please install it now:\n",
    "```\n",
    "pip inst brainrneder\n",
    "```\n",
    "\n",
    "For more details about how to install brainrender, [please check the docs](https://docs.brainrender.info/installation/installation)\n",
    "\n",
    "### Content of this example\n",
    "This notebook shows how to:\n",
    "* Create a `Scene` in brainrender\n",
    "* add `brain regions` to your scene\n",
    "* add a `neuronal morphology` to your scene\n",
    "\n",
    "You can check the [examples](https://github.com/brainglobe/brainrender/tree/master/examples) and the [documentation](https://docs.brainrender.info/) to learn more about how to use brainrender.\n",
    "\n",
    "In particular, if you are planning to use brainrender in a Jupyter Notebook, please read the [docs](https://docs.brainrender.info/usage/using-notebooks) about using brainrender in a notebook, and have a look at the [notebooks workflow example](https://github.com/brainglobe/brainrender/blob/master/examples/notebook_workflow.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from vedo import embedWindow  # for more explanations about these two lines checks the notebooks workflow example\n",
    "embedWindow(None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Creating a scene and adding brain regions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">  acronym   id                           name\n",
       "<span style=\"color: #000080; font-weight: bold\">0</span>    root  <span style=\"color: #000080; font-weight: bold\">997</span>                           root\n",
       "<span style=\"color: #000080; font-weight: bold\">1</span>    grey    <span style=\"color: #000080; font-weight: bold\">8</span>  Basic cell groups and regions\n",
       "<span style=\"color: #000080; font-weight: bold\">2</span>      CH  <span style=\"color: #000080; font-weight: bold\">567</span>                       Cerebrum\n",
       "<span style=\"color: #000080; font-weight: bold\">3</span>     CTX  <span style=\"color: #000080; font-weight: bold\">688</span>                Cerebral cortex\n",
       "<span style=\"color: #000080; font-weight: bold\">4</span>   CTXpl  <span style=\"color: #000080; font-weight: bold\">695</span>                 Cortical plate\n",
       "</pre>\n"
      ],
      "text/plain": [
       "<rich.jupyter.JupyterRenderable at 0x7fa7b839de90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Import Scene\n",
    "from brainrender import Scene  # Scene handles the creation of your rendering!\n",
    "\n",
    "scene = Scene(title='My first rendering')  # create an instance of scene\n",
    "'''\n",
    "If you want to use any of the atlases supported by BrainGlobe's AtlasAPI,\n",
    "specify the atlas name when creating an instance of `Scene`!\n",
    "'''\n",
    "\n",
    "# Adding brain regions\n",
    "scene.add_brain_region('MOs', 'TH', alpha=.5)\n",
    "\n",
    "'''\n",
    "You can add any number of brain regions at once, just specify the regions' acronym or ID numbers.\n",
    "If you are not sure what the acronym/ID is for your region, have a look try:\n",
    "\n",
    "`scene.atlas.lookup_df`\n",
    "\n",
    "or:\n",
    "`print(scene.atlas.hierarchy)`\n",
    "\n",
    "which whill show the hieararchical organization of the atlas' regions:\n",
    "\n",
    "root (997)\n",
    "├── VS (73)\n",
    "│   ├── AQ (140)\n",
    "│   ├── V3 (129)\n",
    "│   ├── V4 (145)\n",
    "│   │   └── V4r (153)\n",
    "│   ├── VL (81)\n",
    "│   │   ├── SEZ (98)\n",
    "│   │   └── chpl (108)\n",
    "│   └── c (164)\n",
    "├── fiber tracts (1009)\n",
    "│   ├── cbf (960)\n",
    "│   │   ├── arb (728)\n",
    "...\n",
    "\n",
    "'''\n",
    "\n",
    "scene.atlas.lookup_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Adding a neuronal morphology\n",
    "Brainrender can load neuronal morphologies from .swc files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #ffa726\">╭──────────────────────────────────╮</span>\n",
       "<span style=\"color: #ffa726\">│</span>  <span style=\"font-weight: bold\">                              </span>  <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>   <span style=\"color: #ff7043; font-weight: bold\">Scene actors</span>                   <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>   <span style=\"color: #ff7043; font-weight: bold\">────────────</span>                   <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>                                  <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>   <span style=\"color: #ffca28; font-weight: bold\">- root</span><span style=\"color: #ef6c00\"> (type: </span><span style=\"color: #ffa726\">brain region</span><span style=\"color: #ef6c00\">)</span>    <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>   <span style=\"color: #ffca28; font-weight: bold\">- title</span><span style=\"color: #ef6c00\"> (type: </span><span style=\"color: #ffa726\">title</span><span style=\"color: #ef6c00\">)</span>          <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>   <span style=\"color: #ffca28; font-weight: bold\">- MOs</span><span style=\"color: #ef6c00\"> (type: </span><span style=\"color: #ffa726\">brain region</span><span style=\"color: #ef6c00\">)</span>     <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>   <span style=\"color: #ffca28; font-weight: bold\">- TH</span><span style=\"color: #ef6c00\"> (type: </span><span style=\"color: #ffa726\">brain region</span><span style=\"color: #ef6c00\">)</span>      <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>   <span style=\"color: #ffca28; font-weight: bold\">- neuron1.swc</span><span style=\"color: #ef6c00\"> (type: </span><span style=\"color: #ffa726\">Neuron</span><span style=\"color: #ef6c00\">)</span>   <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">│</span>                                  <span style=\"color: #ffa726\">│</span>\n",
       "<span style=\"color: #ffa726\">╰──────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "<rich.jupyter.JupyterRenderable at 0x7fa8385cce50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from brainrender.actors import Neuron  # import the Neuron actor class\n",
    "\n",
    "scene.add(Neuron(\"examples/data/neuron1.swc\"))\n",
    "\n",
    "'''\n",
    "Scene.add can be used to add actors to your scene. \n",
    "It accepts instances of the classes defined in brainrender.actors, \n",
    "mesh objects (e.g. loaded with vedo) or path to 3D objects file (e.g. .obj files)\n",
    "\n",
    "To see what actors are in a scene, use scene.content\n",
    "'''\n",
    "scene.content"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rendering\n",
    "Rendering is as simple as `scene.render()`.\n",
    "This will create a pop-up window with the interactive 3D rendering of your scene. \n",
    "When you're done with it, press \"Esc\" to close the window!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "scene.render()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
